package task3.roi;

import java.awt.Rectangle;
import java.security.InvalidParameterException;
import javax.media.jai.PlanarImage;
import task3.pimpmypipe.DataTransformationFilter;
import task3.util.FilterObservable;
import task3.util.ImageTO;

public class RoiFilter
  extends DataTransformationFilter<ImageTO>
{
  private Rectangle rectangle;
  private FilterObservable _observable;
  
  public RoiFilter()
    throws InvalidParameterException
  {
    this._observable = new FilterObservable();
    this.rectangle = new Rectangle(0, 0, 448, 316);
  }
  
  protected void process(ImageTO entity)
  {
    PlanarImage image = PlanarImage.wrapRenderedImage(entity.getEditedImage().getAsBufferedImage(this.rectangle, 
      entity.getEditedImage().getColorModel()));
    
    entity.setEditedImage(image);
    entity.setRoiOffset(this.rectangle.getLocation());
    
    this._observable.setChanged();
    this._observable.notifyObservers(entity);
  }
  
  public Rectangle getRectangle()
  {
    return this.rectangle;
  }
  
  public void setRectangle(Rectangle rectangle)
  {
    this.rectangle = rectangle;
  }
  
  public FilterObservable getObservable()
  {
    return this._observable;
  }
}
